package rmi;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class RmiRegistry {
    public static void main(String[] args) throws RemoteException {
        Registry registry = LocateRegistry.createRegistry(8182);


        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    while (true) {
                        String[] services = registry.list();
                        if (services.length <= 0) {
                            continue;
                        }
                        for (int i = 0; i < services.length; i++) {
                            System.out.println(services[i]);
                        }
                        try {
                            Thread.currentThread().sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }

                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();
        try {
            t.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
